
<%@ page import="com.surelution.projects.crm.GasType" %>
<%@ page import="com.surelution.projects.crm.OwnStation" %>
<%@ page import="com.surelution.projects.crm.StationGas" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:javascript library="jquery" plugin="jquery"/>
        <r:require module="jquery-ui"/>
        <resource:include components="carousel"/>
        <r:layoutResources/>
        <resource:dateChooser />
		<script type="text/javascript" src="${resource(dir:'js/datechooser',file:'datechooser.js')}"></script>
        <g:set var="entityName" value="${message(code: 'ownStation.label', default: 'OwnStation')}" />
        <title><g:message code="default.show.label" args="[entityName]" /></title>
        <script type="text/javascript">
			function g(o){return document.getElementById(o);}
			function HoverLi(m,n){
				g('tb_'+m).className="on";
				g('tbc_'+m).className="dis";
				g('tb_'+n).className="off";
				g('tbc_'+n).className="undis";
			}
		</script>
    </head>
    <body>
        <div class="nav">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
            <span class="menuButton"><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></span>
            <span class="menuButton"><g:link class="search" controller="promoting" action="search" id="${ownStationInstance.id}"><g:message code="default.promoting.label" /></g:link></span>
        </div>
        <div class="body">
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <div class="title">
            	${ownStationInstance.shortName}加油站<label style="font-size:14px;color:blue;">(${fieldValue(bean: ownStationInstance, field: "code")})</label>
            </div>
			<div class="leftContent1" >
				<div class="contentTitle">${year}年站内经营概况</div>
				<div class="saleSum">
		    		<table>
		    	        <tr class="prop">
                            <td valign="top" class="name"><g:message code="ownStation.annualSale.label" default="annualSale" />:</td>
                            
                            <td valign="top" class="value">${fieldValue(bean: ownStationInstance, field: "annualSale")}(吨)</td>
                        </tr>
                        
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="ownStation.noGasAnnualSale.label" default="noGasAnnualSale" />:</td>
                            
                            <td valign="top" class="value">${fieldValue(bean: ownStationInstance, field: "noGasAnnualSale")}</td>
                        </tr>
                       
                       <tr class="prop">
                            <td valign="top" class="name"><g:message code="ownStation.averageSale.label" default="averageSale" />:</td>
                            
                            <td valign="top" class="value">${fieldValue(bean: ownStationInstance, field: "averageSale")}(吨)</td>
                        </tr> 

                       <tr class="prop">
                            <td valign="top" class="name"><g:message code="ownStation.noGasAverageSale.label" default="noGasAverageSale" />:</td>
                            
                            <td valign="top" class="value">${fieldValue(bean: ownStationInstance, field: "noGasAverageSale")}</td>
                        </tr> 
                        
                       <tr class="prop">
                            <td valign="top" class="name"><g:message code="ownStation.annualCardNums.label" default="annualCardNums" />:</td>
                            
                            <td valign="top" class="value">${fieldValue(bean: ownStationInstance, field: "annualCardNums")}</td>
                        </tr> 
                        
                       <tr class="prop">
                            <td valign="top" class="name"><g:message code="ownStation.marketCount.label" default="getMarketCount" />:</td>
                            
                            <td valign="top" class="value">${fieldValue(bean: ownStationInstance, field: "marketCount")}</td>
                        </tr> 

                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="ownStation.marketGasSale.label" default="getMarketGasSale" />:</td>
                            
                            <td valign="top" class="value">${fieldValue(bean: ownStationInstance, field: "marketGasSale")}(吨)</td>
                        </tr>
                        
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="ownStation.marketDieselSale.label" default="getMarketDieselSale" />:</td>
                            
                            <td valign="top" class="value">${fieldValue(bean: ownStationInstance, field: "marketDieselSale")}(吨)</td>
                        </tr>

                  </table>
            	</div>
            	<div class="chartCss">
            		<img alt="chart" src="${grailsApplication.config.chartAPI.location}?cht=p3&chd=t:${ownStationInstance.gasFuel },1&chs=100x100&chtt=${'柴汽比'.encodeAsURL()}+${fieldValue(bean: ownStationInstance, field: "gasFuel")}&chf=bg,s,cac8b9&chco=4d89f9,c6d9fd">
				</div>
				<div class="chartCss">
            		<img alt="chart" src="${grailsApplication.config.chartAPI.location}?cht=p3&chd=t:${ownStationInstance.cardProp/100 },1&chs=100x100&chtt=${'卡销比'.encodeAsURL()}+${fieldValue(bean: ownStationInstance, field: "cardProp")}&chf=bg,s,cac8b9&chco=4d89f9,c6d9fd">
				</div>
				<div class="chart1">
					<img alt="chart" src="${grailsApplication.config.chartAPI.location}?cht=lxy&chxt=x,y&chf=bg,f,efefef&chdl=${'油品销量走势图(吨)'.encodeAsURL()}&chco=FF0000&chs=450x100&chd=t:0,8.3,16.6,24.9,33.2,41.5,49.8,58.1,66.4,74.9,83,91.3,99.6|${numList}&chxt=x,y&chxl=0:|0|1月|2月|3月|4月|5月|6月|7月|8月|9月|10月|11月|12月|1:|0|200|400|600|800|1000">
				</div>
				
            </div>
            <div class="rightContent">
            	<div class="contentTitle">基础信息
            		<g:if test="${ownStationInstance.isLocked==false }">
                    	<g:link action="edit" id="${ownStationInstance.id}" class="editCss" style="color:#275790;">编辑</g:link>
					</g:if>
				</div>
				<div class="dialog2" >
	                <table style="width:400px;padding:0 10px;">
	                    <tbody>
	                        
	                        <tr class="prop">
	                            <td valign="top" class="name1"><g:message code="ownStation.stationArea.label" default="areaName" />:</td>
	                            
	                            <td valign="top" class="value">${fieldValue(bean: ownStationInstance, field: "stationArea.areaName")}</td>
	                        </tr>  
	                        
	                        <tr class="prop">
	                            <td valign="top" class="name1"><g:message code="ownStation.manager.label" default="Manager" />:</td>
	                            
	                            <td valign="top" class="value">${fieldValue(bean: ownStationInstance, field: "manager")}</td>
	                        </tr>
	                        
	                        <tr class="prop">
	                            <td valign="top" class="name1"><g:message code="ownStation.managerTel.label" default="ManagerTel" />:</td>
	                            
	                            <td valign="top" class="value">${fieldValue(bean: ownStationInstance, field: "managerTel")}</td>
	                        </tr>                    
	
	                        <tr class="prop">
	                            <td valign="top" class="name1"><g:message code="ownStation.address.label" default="Address" />:</td>
	                            
	                            <td valign="top" class="value">${fieldValue(bean: ownStationInstance, field: "address")}</td>
	                        </tr>       
	
	                    	<tr class="prop">
	                            <td valign="top" class="name1"><g:message code="ownStation.manageType.label" default="manageType" />:</td>
	                            
	                            <td valign="top" class="value">${fieldValue(bean: ownStationInstance, field: "manageType.manageType")}</td>
	                        </tr>      
	                        
	                        <tr class="prop">
	                            <td valign="top" class="name1"><g:message code="ownStation.level.label" default="level" />:</td>
	                            
	                            <td valign="top" class="value">
								   	<g:if test="${ownStationInstance.level.title.size()>3}"><label title="${ownStationInstance.level.title}">${ownStationInstance.level.title.substring(0,3)}</label> </g:if>
	                            	<g:if test="${ownStationInstance.level.title.size()<3}"><label title="${ownStationInstance.level.title}">${ownStationInstance.level.title}</label></g:if>
	                            	${fieldValue(bean: ownStationInstance, field: "star.title")}、${fieldValue(bean: ownStationInstance, field: "tonLevel.title")}
	                            </td>
	                        </tr>
	                    
	                        <tr class="prop">
	                            <td valign="top" class="name1"><g:message code="ownStation.stationGas.label" default="hasShop" />:</td>
	                            
	                            <td valign="top" class="value">
		        					<g:each in="${com.surelution.projects.crm.StationGas.list()}" var="stationGas">
		        					    <g:if test="${stationGas.station.name==ownStationInstance.name&&stationGas.active==true}">
		        							<a href="${resource(dir:'stationGas/edit')}/${stationGas.id}">${fieldValue(bean: stationGas, field: "gasType.shortName")}</a>、
		        						</g:if>
		        					</g:each>
	                            	<input type="button" onclick="showGasType()" value="添加在售油品" />
	                            	<input type="button" onclick="showPromote()" value="添加促销信息" />
	                            </td>
	                        </tr>
	                     </tbody>
	            	</table>
	        	</div>
	        	 <div id="nav1" >
		        	<ul style="cursor:pointer;">
						<li class="on" id="tb_1" onclick="HoverLi(1,2);" >地图</li>
						<li class="off" id="tb_2" onclick="HoverLi(2,1);">规模</li>
					</ul>
	            	<div id="tbc_1" class="dis">
	            		<div id="smallMap"></div>
	            	</div>
	            	<div id="tbc_2" class="undis" >
		              <table style="padding:20px 40px;">
	                   <tbody>	
	            		<tr class="prop">
                            <td valign="top" class="name"><g:message code="ownStation.generalArea.label" default="generalArea" />:</td>
                            
                            <td valign="top" class="value">${fieldValue(bean: ownStationInstance, field: "generalArea")}</td>
                        </tr>  
                        
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="ownStation.buildingArea.label" default="buildingArea" />:</td>
                            
                            <td valign="top" class="value">${fieldValue(bean: ownStationInstance, field: "buildingArea")}</td>
                        </tr>  

                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="ownStation.coverArea.label" default="coverArea" />:</td>
                            
                            <td valign="top" class="value">${ownStationInstance?.coverArea}</td>
                        </tr>  
                        
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="ownStation.hallArea.label" default="hallArea" />:</td>
                            
                            <td valign="top" class="value">${ownStationInstance?.hallArea}</td>
                        </tr>  
                                                                                                  
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="ownStation.hasShop.label" default="hasShop" />:</td>
                            
                            <td valign="top" class="value">${ownStationInstance.hasShop?"是":"否"}</td>
                        </tr>
                       </tbody>
                      </table>
					</div>
	        	</div>
            
            <script type="text/javascript">
		        $(function() {
		    		$( "#divlog" ).dialog({autoOpen:false, modal:true, height:300, width:450});
		    		$( "#addGasType" ).dialog({autoOpen:false, modal:true, height:300, width:430});
		    		$( "#addPromote" ).dialog({autoOpen:false, modal:true, height:480, width:500});
		    	});
		
		    	function showDialog() {
		    		$( "#divlog" ).dialog("open");
		        }
		    	function showGasType() {
		    		$( "#addGasType" ).dialog("open");
		        }
		    	function showPromote() {
		    		$( "#addPromote" ).dialog("open");
		        }
		    </script>
			<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
			<script type="text/javascript">
				var map;
				function initMap() {
					var lat='${fieldValue(bean: ownStationInstance, field: "latitude")}';
					var lng='${fieldValue(bean: ownStationInstance, field: "longitude")}';
					map = new BMap.Map("smallMap");
					var center = new BMap.Point(lng, lat);
					map.setMapType(BMAP_NORMAL_MAP);
					map.centerAndZoom(center, 15);
					map.addControl(new BMap.NavigationControl());
					map.addControl(new BMap.MapTypeControl({mapTypes:[BMAP_NORMAL_MAP, BMAP_SATELLITE_MAP, BMAP_HYBRID_MAP]}));
					addMarker(lng,lat);
				}			

				function addMarker(x, y){
					var myIcon = new BMap.Icon(
							"http://api.map.baidu.com/img/markers.png" , 
							new BMap.Size(23, 25), 
							{offset: new BMap.Size(32, 32),size:new BMap.Size(23, 25)}
					);
					var point = new BMap.Point(x, y);
					var marker = new BMap.Marker(point, {icon: myIcon}); 
					map.addOverlay(marker);
				}
				
				$(document).ready(function() {
					initMap();
				 });
			</script>
		    <div id="divlog" title="请上传图片！">				
            <g:uploadForm method="post" controller="ownStation" >
			  <g:hiddenField name="id" value="${ownStationInstance?.id}" />
			  <g:hiddenField name="level.id" value="${ownStationInstance?.level.id}" />
			  <g:hiddenField name="starLevel.id" value="${ownStationInstance?.star.id}" />
			  <g:hiddenField name="tonLevel.id" value="${ownStationInstance?.tonLevel.id}" />
			  
              <div class="dialog2" style="padding:20px 0;">
                  <table>				
                  	<tbody>
                    	<tr class="prop">
                        	<td valign="top" class="name">
                            	<label for="station"><g:message code="stationGas.station.label" default="Station" /></label>
                            </td>
                            <td valign="top" class="value ${hasErrors(bean: stationGasInstance, field: 'station', 'errors')}">
                                ${ownStationInstance?.name}
                            </td>
                        </tr>
                            
                        <tr class="prop">
                            <td valign="top" class="name">
                                <label for="title"><g:message code="marketPicture.title.label" default="Title" /></label>
                            </td>
                            <td valign="top" class="value ${hasErrors(bean: StationPictureInstance, field: 'title', 'errors')}">
                                <g:textField name="pictureTitle" value="${StationPictureInstance?.picture?.title}" />
                            </td>
                        </tr>
                          
                        <tr class="prop">
                            <td valign="top" class="name">
                                <label for="description"><g:message code="marketPicture.description.label" default="Description" /></label>
                            </td>
                            <td valign="top" class="value${hasErrors(bean: StationPictureInstance, field: 'description', 'errors')}">
                                <g:textField name="description" value="${StationPictureInstance?.picture?.description}" />
                            </td>
                        </tr>
                      
                        <tr class="prop">
                            <td valign="top" class="name">
                                <label for="title"><g:message code="marketPicture.picture.label" default="Picture" /></label>
                            </td>
                            <td valign="top" >
                            	<g:field type="file" name="OwnPicture"/>
                            </td>
                        </tr>

                        <tr class="prop">
               				<td colspan="2" style="padding:0 0 0 180px;">
               					<g:actionSubmit name="create" class="save" action="updatePic" value="${message(code: 'default.button.create.label', default: 'Create')}" />
               				</td>
                        </tr>
                      </tbody>
                  </table>
              </div>
          	 </g:uploadForm>
          	</div>
          </div>
         <%--添加油品小窗口 	--%>
         	<div id="addGasType" title="添加该站在售油品！">
          	<g:form action="save" controller="stationGas" >
                <div class="dialog2" style="width:300px;">
                    <table>
                        <tbody>
                             <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="station.id"><g:message code="stationGas.station.label" default="Station" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: stationGasInstance, field: 'station', 'errors')}">
                                    <g:hiddenField name="station.id" value="${ownStationInstance?.id}"/>${ownStationInstance?.name}
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="gasType"><g:message code="stationGas.gasType.label" default="Gas Type" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: stationGasInstance, field: 'gasType', 'errors')}">
                                    <g:each in="${com.surelution.projects.crm.GasType.list()}" var="gasType">
                                    	<g:if test="${!StationGas.findByStationAndGasType(ownStationInstance,gasType)||StationGas.findByStationAndGasType(ownStationInstance,gasType).active==false}">
	                                    	<g:checkBox name="gasType.id" value="${gasType.id}"/>${gasType.shortName}<br>
	                                    </g:if>
						    		</g:each>
                                </td>
                            </tr>
                        	<g:hiddenField name="active" value="true"/>
                          	<tr class="prop">
                  				<td colspan="2" style="padding:0 0 0 250px;">
                  					<g:actionSubmit name="create" class="save" action="save" value="${message(code: 'default.button.create.label', default: 'Create')}" />
                  				</td>
                          	</tr>                        
                        </tbody>
                    </table>
                </div>
            </g:form>
            </div>
            
            <div id="addPromote" title="请添加促销信息">
                <g:form action="save" controller="promoting" >
                <div class="dialog2">
                    <table>
                        <tbody>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="stationGas"><g:message code="promoting.stationGas.label" default="Station Gas" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: promotingInstance, field: 'stationGas', 'errors')}">
                                    <select name="stationGas.id"  >
	                                    <g:each in="${com.surelution.projects.crm.StationGas.list()}" var="stationGas">
	        					    		<g:if test="${stationGas.station.name==ownStationInstance.name&&stationGas.active==true}">
							    				<option value="${stationGas.id}">${stationGas.station.shortName},${stationGas.gasType.shortName}</option>
							    			</g:if>
							    		</g:each>
							    	</select>
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="price"><g:message code="promoting.price.label" default="Price" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: promotingInstance, field: 'price', 'errors')}">
                                    <g:textField name="price" value="${fieldValue(bean: promotingInstance, field: 'price')}" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="description"><g:message code="promoting.description.label" default="Description" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: promotingInstance, field: 'description', 'errors')}">
                                    <g:textField name="description" value="${promotingInstance?.description}" style="width:200px;"/>
                                </td>
                            </tr>
                                                    
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="promotingType"><g:message code="promoting.promotingType.label" default="Promoting Type" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: promotingInstance, field: 'promotingType', 'errors')}">
                                    <g:select name="promotingType.id" from="${com.surelution.projects.crm.PromotingType.list()}" optionKey="id" optionValue="title" value="${promotingInstance?.promotingType?.id}"  />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="startDate"><g:message code="promoting.startDate.label" default="Start Date" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: promotingInstance, field: 'startDate', 'errors')}">
                                    <richui:dateChooser name="startDate" locale="zh" format="yyyy-MM-dd" value="${promotingInstance?.startDate}"/>
                                </td>
                            </tr>
                            
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="endDate"><g:message code="promoting.endDate.label" default="End Date" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: promotingInstance, field: 'endDate', 'errors')}">
                                    <richui:dateChooser name="endDate" locale="zh" format="yyyy-MM-dd" value="${promotingInstance?.startDate}"/>
                                </td>
                            </tr>
                            
                          	<tr class="prop">
                  				<td colspan="2" style="padding:0 0 0 300px;">
                  					<g:actionSubmit name="create" class="save" action="save" value="${message(code: 'default.button.create.label', default: 'Create')}" />
                  				</td>
                           </tr>                           
                        </tbody>
                    </table>
                </div>
            </g:form>
            </div>
            <div id="picList" >
		        <div id="pic">
				<g:if test="${ownStationInstance.pictures}">
		        	<g:each in="${ownStationInstance.pictures}" var="picture">
		        		<g:if test="${picture }">
						 	<a href="${resource(dir:'stationPicture/show')}/${picture.id}" title="${picture.picture.title}"><img style="height:150px;width:${150*picture.picture.width/picture.picture.height}px;" src="${resource(dir:'picture/ownStationPic')}/${picture.id}"/></a>
						</g:if>
		        	</g:each>
		        </g:if>
			        <img style="height:150px;width:150px;" src="${resource(dir:'images/')}/waiting.jpg" onclick="showDialog()"/>
				</div>
		     </div>
		 </div>
    </body>
</html>
